//
//  ThreadPoolCPlusPlus.hpp
//  ThreadPool
//
//  Copyright © 2022 sinosun. All rights reserved.
//

#ifndef ThreadPoolCPlusPlus_hpp
#define ThreadPoolCPlusPlus_hpp

#include <stdio.h>
#include <pthread.h>

struct Task;
class TaskQueue;
class ThreadPoolCPlusPlus
{
public:
    ThreadPoolCPlusPlus(int min, int max);
    ~ThreadPoolCPlusPlus();
    
public:
    // 添加任务
    void addTask(Task task);
    // 获取活着的线程个数
    int getAliveNum();
    // 获取忙的线程个数
    int getBusyNum();
    
private:
    // 工作线程的任务函数
    static void* worker(void* arg);
    // 管理线程的任务函数
    static void* manager(void* arg);
    
public:
    // 线程退出
    void threadExit();
    
public:
    TaskQueue* m_tastQ;
    int m_min;
    int m_max;
    int m_liveNum;
    int m_busyNum;
    int m_exitNum;

public:
    pthread_mutex_t m_lock;
    pthread_cond_t m_notEmpty;
    
    pthread_t m_managerID;
    pthread_t* m_threadIDs;
    
    bool m_shutDown = false;
    
};

#endif /* ThreadPoolCPlusPlus_hpp */
